home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Using Image Encoders and Decoders / Copying Individual Frames from a Multiple-Frame Image / GDITEST31.dpr next >
Encoding:
Text File  |  2003-10-15  |  3.0 KB  |  116 lines

  1. program GDITEST31;
  2.  
  3. uses
  4.   Windows,
  5.   Messages,
  6.   SysUtils,
  7.   GDIPAPI,
  8.   GDIPOBJ,
  9.   GDIPUTIL;
  10.  
  11. Procedure OnPaint(DC: HDC);
  12. var
  13.   pageGuid: TGUID;
  14.   encoderClsid: TGUID;
  15.   multi: TGPImage;
  16.   graphic: TGPgraphics;
  17. begin
  18.   graphic:= TGPgraphics.Create(dc);
  19.  
  20.   pageGuid := FrameDimensionPage;
  21.   multi := TGPImage.Create('..\..\Media\Multiframe.tif');
  22.  
  23.   // Get the CLSID of the PNG encoder.
  24.   GetEncoderClsid('image/png', encoderClsid);
  25.  
  26.   // Display and save the first page (index 0).
  27.   multi.SelectActiveFrame(pageGuid, 0);
  28.   graphic.DrawImage(multi, 10, 10);
  29.   multi.Save('Page0.png', encoderClsid, nil);
  30.  
  31.   // Display and save the second page.
  32.   multi.SelectActiveFrame(pageGuid, 1);
  33.   graphic.DrawImage(multi, 220, 10);
  34.   multi.Save('Page1.png', encoderClsid, nil);
  35.  
  36.   // Display and save the third page.
  37.   multi.SelectActiveFrame(pageGuid, 2);
  38.   graphic.DrawImage(multi, 10, 240);
  39.   multi.Save('Page2.png', encoderClsid, nil);
  40.  
  41.   // Display and save the fourth page.
  42.   multi.SelectActiveFrame(pageGuid, 3);
  43.   graphic.DrawImage(multi, 220, 150);
  44.   multi.Save('Page3.png', encoderClsid, nil);
  45.  
  46.   multi.Free;
  47.   graphic.Free;
  48. end;
  49.  
  50.  
  51. function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
  52. var
  53.   Handle: HDC;
  54.   ps: PAINTSTRUCT;
  55. begin
  56.   case message of
  57.     WM_PAINT:
  58.       begin
  59.         Handle := BeginPaint(Wnd, ps);
  60.         OnPaint(Handle);
  61.         EndPaint(Wnd, ps);
  62.         result := 0;
  63.       end;
  64.  
  65.     WM_DESTROY:
  66.       begin
  67.         PostQuitMessage(0);
  68.         result := 0;
  69.       end;
  70.  
  71.    else
  72.       result := DefWindowProc(Wnd, message, wParam, lParam);
  73.    end;
  74. end;
  75.  
  76. var
  77.   hWnd     : THandle;
  78.   Msg      : TMsg;
  79.   wndClass : TWndClass;
  80. begin
  81.    wndClass.style          := CS_HREDRAW or CS_VREDRAW;
  82.    wndClass.lpfnWndProc    := @WndProc;
  83.    wndClass.cbClsExtra     := 0;
  84.    wndClass.cbWndExtra     := 0;
  85.    wndClass.hInstance      := hInstance;
  86.    wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
  87.    wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
  88.    wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
  89.    wndClass.lpszMenuName   := nil;
  90.    wndClass.lpszClassName  := 'GettingStarted';
  91.  
  92.    RegisterClass(wndClass);
  93.  
  94.    hWnd := CreateWindow(
  95.       'GettingStarted',       // window class name
  96.       'Copying Individual Frames from a Multiple-Frame Image',       // window caption
  97.       WS_OVERLAPPEDWINDOW,    // window style
  98.       Integer(CW_USEDEFAULT), // initial x position
  99.       Integer(CW_USEDEFAULT), // initial y position
  100.       Integer(CW_USEDEFAULT), // initial x size
  101.       Integer(CW_USEDEFAULT), // initial y size
  102.       0,                      // parent window handle
  103.       0,                      // window menu handle
  104.       hInstance,              // program instance handle
  105.       nil);                   // creation parameters
  106.  
  107.    ShowWindow(hWnd, SW_SHOW);
  108.    UpdateWindow(hWnd);
  109.  
  110.    while(GetMessage(msg, 0, 0, 0)) do
  111.    begin
  112.       TranslateMessage(msg);
  113.       DispatchMessage(msg);
  114.    end;
  115. end.
  116.